/************************************************************
 * Project Name		[Thinking_In_Java]
 * File Name     	[pkg_02_oop.inner_classes.Example_03_Static_Inner_Class.java]
 * Creation Date 	[21-Jun-2014]
 * 
 * Copyright© ge.y.yang@gmail.com All Rights Reserved
 * 
 * Work hard, play harder, think big and keep fit
 ************************************************************/
package pkg_02_oop.inner_classes;

/**
 * 静态内部类
 * 
 * @author 不落的太阳(Sean Yang)
 * @version 1.0
 * @since JDK 6
 * 
 */
public class Example_03_Static_Inner_Class {

	/**
	 * 静态内部类
	 * 
	 * 
	 * @author 不落的太阳(Sean Yang)
	 * @version 1.0
	 * @since JDK 6
	 * 
	 */
	public static class Pair {

		private double first;
		private double second;

		public Pair(double first, double second) {
			this.first = first;
			this.second = second;
		}

		/**
		 * return the first number of pair
		 * 
		 * @return first number
		 */
		public double getFirst() {
			return first;
		}

		/**
		 * return the second number of pair
		 * 
		 * @return second number
		 */
		public double getSecond() {
			return second;
		}

		/**
		 * toString
		 * 
		 * @return string value of pair
		 */
		@Override
		public String toString() {
			return "Pair [first=" + first + ", second=" + second + "]";
		}
	}

	/**
	 * 查找一个double数组中的最大值和最小值
	 * 
	 * 当一个方法返回值有多个的时候, 可以考虑使用内部类来解决问题
	 * 
	 * @param values
	 * @return Pair对象
	 */
	public static Pair minmax(double[] values) {
		double min = Double.MAX_VALUE;
		double max = Double.MIN_VALUE;

		for (double d : values) {
			if (min > d) {
				min = d;
			}
			if (max < d) {
				max = d;
			}
		}
		return new Pair(min, max);
	}

	/**
	 * 测试方法
	 * 
	 * @param args
	 *            命令行参数
	 */
	public static void main(String[] args) {
		double[] values = { 10.0, 11.0, 12.0, 13.0, 14.0, 15.0 };
		Example_03_Static_Inner_Class.Pair pair = Example_03_Static_Inner_Class
				.minmax(values);
		System.out.println(pair);
	}
}
